package com.mirzabros.chexmo;

import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.view.View.OnClickListener;
import android.view.inputmethod.EditorInfo;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.TextView.OnEditorActionListener;

import com.mirzabros.chexmo.Chexmo_Chk_Pin.URLCache;
import com.mirzabros.chexmo.contant.Chexmo_Urls;
import com.mirzabros.chexmo.service.Chexmo_CheckPin_Service;

public class Chexmo_Admin_Login extends Activity{
	
	private ImageView logoimg;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		this.requestWindowFeature(Window.FEATURE_NO_TITLE);
		this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
				WindowManager.LayoutParams.FLAG_FULLSCREEN);

		setContentView(R.layout.chexmo_admin_login_dialog);
		
		final EditText username = (EditText)findViewById(R.id.txt_username);
		final EditText pass_text = (EditText)findViewById(R.id.txt_password);
		
		final Button btnchkin  = (Button)findViewById(R.id.btnLoginform);
		
		pass_text.setOnEditorActionListener(new OnEditorActionListener() {
			@Override
			public boolean onEditorAction(TextView v, int actionId,
					KeyEvent event) {
				if (actionId == EditorInfo.IME_ACTION_DONE) {
					btnchkin.performClick();
				}
				return false;
			}
		});
		
		Bundle extras = getIntent().getExtras();
		if (extras != null) {
			final String user = extras.getString("user");
			final String pass = extras.getString("pass");
			final String code = extras.getString("code");
			final String Logo = extras.getString("logo");
			final String country = extras.getString("country");
			
			username.setText(user);
			
			btnchkin.setOnClickListener(new OnClickListener() {
				
				@Override
				public void onClick(View v) {

					if(pass_text.getText().toString().equals(pass)){
						Intent intent = new Intent(Chexmo_Admin_Login.this,Chexmo_User_Webview.class);
						intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
						Bundle bundle = new Bundle();
						bundle.putString("user", user);
						bundle.putString("pass", pass);
						bundle.putString("code", code);
						bundle.putString("country", country);
						bundle.putString("logo", Logo);
						bundle.putInt("lockvisible", 1);
						intent.putExtras(bundle);
						startActivity(intent);
						finish();
					}else{
						Toast toast = Toast.makeText(Chexmo_Admin_Login.this, "Admin Password Incorrect !!", Toast.LENGTH_SHORT);
						toast.show();
						finish();
					}
				}
			});
			
			
		}
	}
	
	
}
